*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Run project scripts in sequence.
*-------------------------------------------------------------------------------


* Control execution logic
*-------------------------------------------------------------------------------

* Set default execution behavior
local install "--install-ados"
local build = 1
local share = 1

* Indicate whether to run specifications
global estimate = 1

* Let user override default behavior via command-line arguments
while "`1'" != "" {
	if "`1'" == "--no-install" {
		local install
	}
	else if "`1'" == "--no-build" {
		local build = 0
	}
	else if "`1'" == "--no-share" {
		local share = 0
	}
	else if "`1'" == "--no-estimate" {
		global estimate = 0
	}
	else {
		display as error _n `"main.do: "`1'" is an invalid command-line option"'
		exit = 9
	}

	macro shift
}


* Configure settings and flesh out directory structure
*-------------------------------------------------------------------------------

* Configure settings
do "./profile.do" `install'

* Create subdirectories
capture mkdir "$basepath/data"
capture mkdir "$basepath/data/derived"
capture mkdir "$basepath/data/raw"
capture mkdir "$basepath/logs"
capture mkdir "$basepath/logs/build"
capture mkdir "$basepath/logs/share"
capture mkdir "$basepath/models"
capture mkdir "$basepath/output"


* Start logging
*-------------------------------------------------------------------------------

capture log close mainlog
log using "${basepath}/logs/main.log", name(mainlog) text replace


* Run data-preparation scripts
*-------------------------------------------------------------------------------

if `build' {
	* Prepare auxiliary files
	do "$basepath/code/build/geo_builder.do"
	do "$basepath/code/build/turning_points.do"

	* Prepare CPS basic monthly files
	do "$basepath/code/build/cps_bms_builder.do"
	do "$basepath/code/build/cps_bms_sampler.do"
	do "$basepath/code/build/cps_bms_raking.do"

	* Prepare other datasets
	do "$basepath/code/build/cps_asec_builder.do"
	do "$basepath/code/build/atus_builder.do"
	do "$basepath/code/build/sass_builder.do"

	* Classify states by the timing of school closures
	do "$basepath/code/build/classify_states.do"
}


* Run analyses
*-------------------------------------------------------------------------------

if `share' {
	do "$basepath/code/share/annuals.do"
	do "$basepath/code/share/between.do"
	do "$basepath/code/share/calendars.do"
	do "$basepath/code/share/careers.do"
	do "$basepath/code/share/couples.do"
	do "$basepath/code/share/edemp.do"
	do "$basepath/code/share/edexits.do"
	do "$basepath/code/share/evolution.do"
	do "$basepath/code/share/explain_demogs.do"
	do "$basepath/code/share/heterogeneity.do"
	do "$basepath/code/share/hhstatus.do"
	do "$basepath/code/share/job_decomp.do"
	do "$basepath/code/share/life_cycle.do"
	do "$basepath/code/share/logs_levels.do"
	do "$basepath/code/share/margins.do"
	do "$basepath/code/share/motivation.do"
	do "$basepath/code/share/multiple_kids.do"
	do "$basepath/code/share/occ_flows.do"
	do "$basepath/code/share/overall.do"
	do "$basepath/code/share/reasons.do"
	do "$basepath/code/share/recurrence.do"
	do "$basepath/code/share/sass.do"
	do "$basepath/code/share/sorting.do"
	do "$basepath/code/share/stocks_flows.do"
	do "$basepath/code/share/summer_layoffs.do"
	do "$basepath/code/share/sumstats.do"
	do "$basepath/code/share/synchrony.do"
	do "$basepath/code/share/timeuse.do"
	do "$basepath/code/share/twomonth.do"
	do "$basepath/code/share/unconnected.do"
	do "$basepath/code/share/unpaid_leave.do"
	do "$basepath/code/share/vacation.do"
	do "$basepath/code/share/winter_sectors.do"
}

* Close the log file
log close mainlog
